<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <title>关于最小生成树的一切 - L_B__</title><meta name="referrer" content="no-referrer">
<meta name="description" content="关于最小生成树的一切"><meta property="og:title" content="关于最小生成树的一切" />
<meta property="og:description" content="关于最小生成树的一切" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://acking-you.github.io/posts/%E5%85%B3%E4%BA%8E%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91%E7%9A%84%E4%B8%80%E5%88%87/" /><meta property="og:image" content="https://acking-you.github.io/logo.png"/><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2022-12-19T00:00:00+00:00" />
<meta property="article:modified_time" content="2022-12-19T00:00:00+00:00" />

<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://acking-you.github.io/logo.png"/>

<meta name="twitter:title" content="关于最小生成树的一切"/>
<meta name="twitter:description" content="关于最小生成树的一切"/>
<meta name="application-name" content="FeelIt">
<meta name="apple-mobile-web-app-title" content="FeelIt"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="canonical" href="https://acking-you.github.io/posts/%E5%85%B3%E4%BA%8E%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91%E7%9A%84%E4%B8%80%E5%88%87/" /><link rel="prev" href="https://acking-you.github.io/posts/zipgzipbzip2tar%E6%9C%89%E4%BD%95%E8%81%94%E7%B3%BB/" /><link rel="next" href="https://acking-you.github.io/posts/%E5%85%B3%E4%BA%8E%E5%B9%B6%E6%9F%A5%E9%9B%86%E7%9A%84%E4%B8%80%E5%88%87/" /><link rel="stylesheet" href="/css/page.min.css"><link rel="stylesheet" href="/css/home.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "关于最小生成树的一切",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/acking-you.github.io\/posts\/%E5%85%B3%E4%BA%8E%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91%E7%9A%84%E4%B8%80%E5%88%87\/"
        },"genre": "posts","keywords": "关于最小生成树的一切","wordcount":  1629 ,
        "url": "https:\/\/acking-you.github.io\/posts\/%E5%85%B3%E4%BA%8E%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91%E7%9A%84%E4%B8%80%E5%88%87\/","datePublished": "2022-12-19T00:00:00+00:00","dateModified": "2022-12-19T00:00:00+00:00","publisher": {
            "@type": "Organization",
            "name": "作者"},"author": {
                "@type": "Person",
                "name": "作者"
            },"description": "关于最小生成树的一切"
    }
    </script></head><body data-header-desktop="auto" data-header-mobile="auto"><script>(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="L_B__">L_B__</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="#" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="L_B__">L_B__</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="#" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="#" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><div class="menu-item"><a href="javascript:void(0);" class="theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div></div>
    </div>
</header><div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div><main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single" data-toc="disable"><div class="featured-image"><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/img_convert/acea126d07748d6630f37b1b481e5d73.png#pic_center"
        data-srcset="https://img-blog.csdnimg.cn/img_convert/acea126d07748d6630f37b1b481e5d73.png#pic_center, https://img-blog.csdnimg.cn/img_convert/acea126d07748d6630f37b1b481e5d73.png#pic_center 1.5x, https://img-blog.csdnimg.cn/img_convert/acea126d07748d6630f37b1b481e5d73.png#pic_center 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/img_convert/acea126d07748d6630f37b1b481e5d73.png#pic_center"
        title="关于最小生成树的一切" /></div><div class="single-card" data-image="true"><h2 class="single-title animated flipInX">关于最小生成树的一切</h2><div class="post-meta">
                <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>作者</a></span>&nbsp;<span class="post-category">出版于  <a href="/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91/"><i class="far fa-folder fa-fw"></i>数据结构——最小生成树</a></span></div>
                <div class="post-meta-line"><span><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2022-12-19">2022-12-19</time></span>&nbsp;<span><i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 1629 字</span>&nbsp;
                    <span><i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 4 分钟</span>&nbsp;</div>
            </div>
            
            <hr><div class="details toc" id="toc-static"  data-kept="">
                    <div class="details-summary toc-title">
                        <span>目录</span>
                        <span><i class="details-icon fas fa-angle-right"></i></span>
                    </div>
                    <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#初识最小生成树">初识最小生成树</a></li>
    <li><a href="#切分定理">切分定理</a>
      <ul>
        <li><a href="#切分定理的证明">切分定理的证明</a></li>
      </ul>
    </li>
    <li><a href="#kruskal-算法以边扩散">Kruskal 算法(以边扩散)</a>
      <ul>
        <li><a href="#练习题--连接所有点的最小费用">练习题&ndash;连接所有点的最小费用</a></li>
        <li><a href="#解题代码">解题代码</a></li>
      </ul>
    </li>
    <li><a href="#prim算法以顶点扩散">Prim算法(以顶点扩散)</a>
      <ul>
        <li><a href="#kruskal-算法和-prim-算法区别">「Kruskal 算法」和 「Prim 算法」区别</a></li>
        <li><a href="#时间复杂度">时间复杂度</a></li>
        <li><a href="#空间复杂度">空间复杂度</a></li>
        <li><a href="#练习题--连接所有点的最小费用-1">练习题&ndash;连接所有点的最小费用</a></li>
        <li><a href="#解题代码-1">解题代码</a></li>
      </ul>
    </li>
  </ul>
</nav></div>
                </div><div class="content" id="content"><h2 id="初识最小生成树">初识最小生成树</h2>
<p>首先，小伙伴们可能要冒出第一个问题了。什么是生成树？生成树 指的是「无向图」中，具有该图的 全部顶点 且 边数最少 的连通子图。「图8. 生成树」中，所有粉色线条组成的一棵树[(A, B), (A, C), (A, D), (A, E)]，就是该无向图的其中一个生成树。其实[(A, E),(A, B), (B, C), (C, D)]也是该无向图的一个生成树。由此可见，一个「无向图」的生成树可以是多个。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/a14684767e51436cb8d2a871f8a8f532.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0,size_16,color_FFFFFF,t_70"
        data-srcset="https://img-blog.csdnimg.cn/a14684767e51436cb8d2a871f8a8f532.png?x-oss-process=image/watermark%2ctype_ZmFuZ3poZW5naGVpdGk%2cshadow_10%2ctext_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0%2csize_16%2ccolor_FFFFFF%2ct_70, https://img-blog.csdnimg.cn/a14684767e51436cb8d2a871f8a8f532.png?x-oss-process=image/watermark%2ctype_ZmFuZ3poZW5naGVpdGk%2cshadow_10%2ctext_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0%2csize_16%2ccolor_FFFFFF%2ct_70 1.5x, https://img-blog.csdnimg.cn/a14684767e51436cb8d2a871f8a8f532.png?x-oss-process=image/watermark%2ctype_ZmFuZ3poZW5naGVpdGk%2cshadow_10%2ctext_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0%2csize_16%2ccolor_FFFFFF%2ct_70 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/a14684767e51436cb8d2a871f8a8f532.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0,size_16,color_FFFFFF,t_70"
        title="图8生成树" />
那么再了解了什么是生成树后，小伙伴们可能又要冒出第二个问题了。什么是最小生成树。<strong>最小生成树</strong>指的是「加权无向图」中总权重最小的生成树。「图9. 最小生成树」中，所有绿色线条组成的一颗生成树[(A, E),(A, B), (B, C), (C, D)]，就是该加权无向图的其中一个最小生成树。其实[(A, E), (E, D), (A, B), (B, C)]也是该加权无向图的另一个最小生成树，由此可见，一个「加权无向图」的最小生成树可以是多个。
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/582d461503e64d3183dac8ee51cbc014.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0,size_16,color_FFFFFF,t_70"
        data-srcset="https://img-blog.csdnimg.cn/582d461503e64d3183dac8ee51cbc014.png?x-oss-process=image/watermark%2ctype_ZmFuZ3poZW5naGVpdGk%2cshadow_10%2ctext_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0%2csize_16%2ccolor_FFFFFF%2ct_70, https://img-blog.csdnimg.cn/582d461503e64d3183dac8ee51cbc014.png?x-oss-process=image/watermark%2ctype_ZmFuZ3poZW5naGVpdGk%2cshadow_10%2ctext_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0%2csize_16%2ccolor_FFFFFF%2ct_70 1.5x, https://img-blog.csdnimg.cn/582d461503e64d3183dac8ee51cbc014.png?x-oss-process=image/watermark%2ctype_ZmFuZ3poZW5naGVpdGk%2cshadow_10%2ctext_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0%2csize_16%2ccolor_FFFFFF%2ct_70 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/582d461503e64d3183dac8ee51cbc014.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0,size_16,color_FFFFFF,t_70"
        title="图9.最小生成树" />
那么在该章节中，我们将学习下「生成最小生成树」的两种算法以及「切分定理」：</p>
<ul>
<li>切分定理</li>
<li>Kruskal 算法</li>
<li>Prim 算法</li>
</ul>
<hr>
<h2 id="切分定理">切分定理</h2>
<p>「切分」是什么呢？很多的定理都是以人的名字命名的，但是「切分」并不是一个人的名字。在「切分定理」中有两个基本概念，我们需要了解下：</p>
<ul>
<li>切分：将「图」切成两个部分，称之为一个「切分」。「图 10. 切分图」就是一个「切分」，其中(B, A, E)为一个部分，(C, D)为另外一个部分。</li>
<li>横切边：如果一条边连接的两个顶点属于切分的两个部分，这个边称为「横切边」。在「图10. 切分图」中，(B, C), (A, C), (A, D), (E, D) 均为「横切边」。
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/06ceab4eee3d4736825babc45eb8348a.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0,size_16,color_FFFFFF,t_70"
        data-srcset="https://img-blog.csdnimg.cn/06ceab4eee3d4736825babc45eb8348a.png?x-oss-process=image/watermark%2ctype_ZmFuZ3poZW5naGVpdGk%2cshadow_10%2ctext_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0%2csize_16%2ccolor_FFFFFF%2ct_70, https://img-blog.csdnimg.cn/06ceab4eee3d4736825babc45eb8348a.png?x-oss-process=image/watermark%2ctype_ZmFuZ3poZW5naGVpdGk%2cshadow_10%2ctext_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0%2csize_16%2ccolor_FFFFFF%2ct_70 1.5x, https://img-blog.csdnimg.cn/06ceab4eee3d4736825babc45eb8348a.png?x-oss-process=image/watermark%2ctype_ZmFuZ3poZW5naGVpdGk%2cshadow_10%2ctext_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0%2csize_16%2ccolor_FFFFFF%2ct_70 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/06ceab4eee3d4736825babc45eb8348a.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0,size_16,color_FFFFFF,t_70"
        title="10.切分图" />
再了解了切分定理的基础概念之后，我们就需要学习下「切分定理」了。切分定理是 Kruskal 算法和 Prim 算法的重要的理论支撑。那么什么是「切分定理」呢？根据 维基百科 的定义，「切分定理」指的是：</li>
</ul>
<blockquote>
<p>在一幅连通加权无向图中，给定任意的切分，如果有一条横切边的权值严格小于所有其他横切边，则这条边必然属于图的最小生成树中的一条边。</p>
</blockquote>
<h3 id="切分定理的证明">切分定理的证明</h3>
<p><a href="https://www.youtube.com/watch?v=ZEo4VGA8RcA" target="_blank" rel="noopener noreffer">视频链接</a></p>
<hr>
<h2 id="kruskal-算法以边扩散">Kruskal 算法(以边扩散)</h2>
<p>「Kruskal 算法」是求解「加权无向图」的「最小生成树」的一种算法。
<a href="https://www.youtube.com/watch?v=NVt4Y1VUp9g" target="_blank" rel="noopener noreffer">视频链接</a></p>
<p><strong>时间复杂度</strong>:
$O(E*logE)$
$E$ 表示边数。</p>
<p><strong>空间复杂度</strong>：
$O(V)$
$V$表示顶点数。</p>
<h3 id="练习题--连接所有点的最小费用">练习题&ndash;连接所有点的最小费用</h3>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/dd0a6038d2a349e9945d92fa3ab9f2cb.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0,size_16,color_FFFFFF,t_70"
        data-srcset="https://img-blog.csdnimg.cn/dd0a6038d2a349e9945d92fa3ab9f2cb.png?x-oss-process=image/watermark%2ctype_ZmFuZ3poZW5naGVpdGk%2cshadow_10%2ctext_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0%2csize_16%2ccolor_FFFFFF%2ct_70, https://img-blog.csdnimg.cn/dd0a6038d2a349e9945d92fa3ab9f2cb.png?x-oss-process=image/watermark%2ctype_ZmFuZ3poZW5naGVpdGk%2cshadow_10%2ctext_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0%2csize_16%2ccolor_FFFFFF%2ct_70 1.5x, https://img-blog.csdnimg.cn/dd0a6038d2a349e9945d92fa3ab9f2cb.png?x-oss-process=image/watermark%2ctype_ZmFuZ3poZW5naGVpdGk%2cshadow_10%2ctext_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0%2csize_16%2ccolor_FFFFFF%2ct_70 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/dd0a6038d2a349e9945d92fa3ab9f2cb.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUwOTQ1NTA0,size_16,color_FFFFFF,t_70"
        title="题目图" />
<a href="https://www.youtube.com/watch?v=1HKZk6IyxUY" target="_blank" rel="noopener noreffer">视频讲解</a></p>
<h3 id="解题代码">解题代码</h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="kd">class</span> <span class="nc">Solution</span> <span class="o">{</span>
    <span class="c1">// Kruskal Algorithm
</span><span class="c1"></span>    <span class="kd">public</span> <span class="kt">int</span> <span class="nf">minCostConnectPoints</span><span class="o">(</span><span class="kt">int</span><span class="o">[][]</span> <span class="n">points</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">if</span> <span class="o">(</span><span class="n">points</span> <span class="o">==</span> <span class="kc">null</span> <span class="o">||</span> <span class="n">points</span><span class="o">.</span><span class="na">length</span> <span class="o">==</span> <span class="n">0</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">return</span> <span class="n">0</span><span class="o">;</span>
        <span class="o">}</span>
        <span class="kt">int</span> <span class="n">size</span> <span class="o">=</span> <span class="n">points</span><span class="o">.</span><span class="na">length</span><span class="o">;</span>
        <span class="n">PriorityQueue</span><span class="o">&lt;</span><span class="n">Edge</span><span class="o">&gt;</span> <span class="n">pq</span> <span class="o">=</span> <span class="k">new</span> <span class="n">PriorityQueue</span><span class="o">&lt;</span><span class="n">Edge</span><span class="o">&gt;((</span><span class="n">x</span><span class="o">,</span> <span class="n">y</span><span class="o">)</span> <span class="o">-&gt;</span> <span class="n">x</span><span class="o">.</span><span class="na">cost</span> <span class="o">-</span> <span class="n">y</span><span class="o">.</span><span class="na">cost</span><span class="o">);</span>
        <span class="n">UnionFind</span> <span class="n">uf</span> <span class="o">=</span> <span class="k">new</span> <span class="n">UnionFind</span><span class="o">(</span><span class="n">size</span><span class="o">);</span>

        <span class="k">for</span> <span class="o">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">0</span><span class="o">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">size</span><span class="o">;</span> <span class="n">i</span><span class="o">++)</span> <span class="o">{</span>
            <span class="k">for</span> <span class="o">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="n">i</span><span class="o">+</span><span class="n">1</span><span class="o">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">size</span><span class="o">;</span> <span class="n">j</span><span class="o">++)</span> <span class="o">{</span>
                <span class="kt">int</span><span class="o">[]</span> <span class="n">coordinate1</span> <span class="o">=</span> <span class="n">points</span><span class="o">[</span><span class="n">i</span><span class="o">];</span>
                <span class="kt">int</span><span class="o">[]</span> <span class="n">coordinate2</span> <span class="o">=</span> <span class="n">points</span><span class="o">[</span><span class="n">j</span><span class="o">];</span>
                <span class="c1">// Calculate the distance between two coordinates.
</span><span class="c1"></span>                <span class="kt">int</span> <span class="n">cost</span> <span class="o">=</span> <span class="n">Math</span><span class="o">.</span><span class="na">abs</span><span class="o">(</span><span class="n">coordinate1</span><span class="o">[</span><span class="n">0</span><span class="o">]</span> <span class="o">-</span> <span class="n">coordinate2</span><span class="o">[</span><span class="n">0</span><span class="o">])</span> <span class="o">+</span> <span class="n">Math</span><span class="o">.</span><span class="na">abs</span><span class="o">(</span><span class="n">coordinate1</span><span class="o">[</span><span class="n">1</span><span class="o">]</span> <span class="o">-</span> <span class="n">coordinate2</span><span class="o">[</span><span class="n">1</span><span class="o">]);</span>
                <span class="n">Edge</span> <span class="n">edge</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Edge</span><span class="o">(</span><span class="n">i</span><span class="o">,</span> <span class="n">j</span><span class="o">,</span> <span class="n">cost</span><span class="o">);</span>
                <span class="n">pq</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">edge</span><span class="o">);</span>
            <span class="o">}</span>
        <span class="o">}</span>

        <span class="kt">int</span> <span class="n">result</span> <span class="o">=</span> <span class="n">0</span><span class="o">;</span>
        <span class="kt">int</span> <span class="n">count</span> <span class="o">=</span> <span class="n">size</span> <span class="o">-</span> <span class="n">1</span><span class="o">;</span>
        <span class="k">while</span> <span class="o">(</span> <span class="n">pq</span><span class="o">.</span><span class="na">size</span><span class="o">()</span> <span class="o">&gt;</span> <span class="n">0</span> <span class="o">&amp;&amp;</span> <span class="n">count</span> <span class="o">&gt;</span> <span class="n">0</span> <span class="o">)</span> <span class="o">{</span>
            <span class="n">Edge</span> <span class="n">e</span> <span class="o">=</span> <span class="n">pq</span><span class="o">.</span><span class="na">poll</span><span class="o">();</span>
            <span class="k">if</span> <span class="o">(</span> <span class="o">!</span><span class="n">uf</span><span class="o">.</span><span class="na">connected</span><span class="o">(</span><span class="n">e</span><span class="o">.</span><span class="na">point1</span><span class="o">,</span> <span class="n">e</span><span class="o">.</span><span class="na">point2</span><span class="o">))</span> <span class="o">{</span>
                <span class="n">uf</span><span class="o">.</span><span class="na">union</span><span class="o">(</span><span class="n">e</span><span class="o">.</span><span class="na">point1</span><span class="o">,</span> <span class="n">e</span><span class="o">.</span><span class="na">point2</span><span class="o">);</span>
                <span class="n">result</span> <span class="o">+=</span> <span class="n">e</span><span class="o">.</span><span class="na">cost</span><span class="o">;</span>
                <span class="n">count</span><span class="o">--;</span>
            <span class="o">}</span>
        <span class="o">}</span>
        <span class="k">return</span> <span class="n">result</span><span class="o">;</span>
    <span class="o">}</span>

    <span class="kd">class</span> <span class="nc">Edge</span> <span class="o">{</span>
        <span class="kt">int</span> <span class="n">point1</span><span class="o">;</span>
        <span class="kt">int</span> <span class="n">point2</span><span class="o">;</span>
        <span class="kt">int</span> <span class="n">cost</span><span class="o">;</span>

        <span class="n">Edge</span><span class="o">(</span><span class="kt">int</span> <span class="n">point1</span><span class="o">,</span> <span class="kt">int</span> <span class="n">point2</span><span class="o">,</span> <span class="kt">int</span> <span class="n">cost</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="na">point1</span> <span class="o">=</span> <span class="n">point1</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="na">point2</span> <span class="o">=</span> <span class="n">point2</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="na">cost</span> <span class="o">=</span> <span class="n">cost</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">}</span>

    <span class="kd">class</span> <span class="nc">UnionFind</span> <span class="o">{</span>
        <span class="kt">int</span> <span class="n">root</span><span class="o">[];</span>
        <span class="kt">int</span> <span class="n">rank</span><span class="o">[];</span>

        <span class="kd">public</span> <span class="nf">UnionFind</span><span class="o">(</span><span class="kt">int</span> <span class="n">size</span><span class="o">)</span> <span class="o">{</span>
            <span class="n">root</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">int</span><span class="o">[</span><span class="n">size</span><span class="o">];</span>
            <span class="n">rank</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">int</span><span class="o">[</span><span class="n">size</span><span class="o">];</span>
            <span class="k">for</span> <span class="o">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">0</span><span class="o">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">size</span><span class="o">;</span> <span class="n">i</span><span class="o">++)</span> <span class="o">{</span>
                <span class="n">root</span><span class="o">[</span><span class="n">i</span><span class="o">]</span> <span class="o">=</span> <span class="n">i</span><span class="o">;</span>
                <span class="n">rank</span><span class="o">[</span><span class="n">i</span><span class="o">]</span> <span class="o">=</span> <span class="n">1</span><span class="o">;</span> 
            <span class="o">}</span>
        <span class="o">}</span>

        <span class="kd">public</span> <span class="kt">int</span> <span class="nf">find</span><span class="o">(</span><span class="kt">int</span> <span class="n">x</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">if</span> <span class="o">(</span><span class="n">x</span> <span class="o">==</span> <span class="n">root</span><span class="o">[</span><span class="n">x</span><span class="o">])</span> <span class="o">{</span>
                <span class="k">return</span> <span class="n">x</span><span class="o">;</span>
            <span class="o">}</span>
            <span class="k">return</span> <span class="n">root</span><span class="o">[</span><span class="n">x</span><span class="o">]</span> <span class="o">=</span> <span class="n">find</span><span class="o">(</span><span class="n">root</span><span class="o">[</span><span class="n">x</span><span class="o">]);</span>
        <span class="o">}</span>

        <span class="kd">public</span> <span class="kt">void</span> <span class="nf">union</span><span class="o">(</span><span class="kt">int</span> <span class="n">x</span><span class="o">,</span> <span class="kt">int</span> <span class="n">y</span><span class="o">)</span> <span class="o">{</span>
            <span class="kt">int</span> <span class="n">rootX</span> <span class="o">=</span> <span class="n">find</span><span class="o">(</span><span class="n">x</span><span class="o">);</span>
            <span class="kt">int</span> <span class="n">rootY</span> <span class="o">=</span> <span class="n">find</span><span class="o">(</span><span class="n">y</span><span class="o">);</span>
            <span class="k">if</span> <span class="o">(</span><span class="n">rootX</span> <span class="o">!=</span> <span class="n">rootY</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">if</span> <span class="o">(</span><span class="n">rank</span><span class="o">[</span><span class="n">rootX</span><span class="o">]</span> <span class="o">&gt;</span> <span class="n">rank</span><span class="o">[</span><span class="n">rootY</span><span class="o">])</span> <span class="o">{</span>
                    <span class="n">root</span><span class="o">[</span><span class="n">rootY</span><span class="o">]</span> <span class="o">=</span> <span class="n">rootX</span><span class="o">;</span>
                <span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="n">rank</span><span class="o">[</span><span class="n">rootX</span><span class="o">]</span> <span class="o">&lt;</span> <span class="n">rank</span><span class="o">[</span><span class="n">rootY</span><span class="o">])</span> <span class="o">{</span>
                    <span class="n">root</span><span class="o">[</span><span class="n">rootX</span><span class="o">]</span> <span class="o">=</span> <span class="n">rootY</span><span class="o">;</span>
                <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
                    <span class="n">root</span><span class="o">[</span><span class="n">rootY</span><span class="o">]</span> <span class="o">=</span> <span class="n">rootX</span><span class="o">;</span>
                    <span class="n">rank</span><span class="o">[</span><span class="n">rootX</span><span class="o">]</span> <span class="o">+=</span> <span class="n">1</span><span class="o">;</span>
                <span class="o">}</span>
            <span class="o">}</span>
        <span class="o">}</span>

        <span class="kd">public</span> <span class="kt">boolean</span> <span class="nf">connected</span><span class="o">(</span><span class="kt">int</span> <span class="n">x</span><span class="o">,</span> <span class="kt">int</span> <span class="n">y</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">return</span> <span class="n">find</span><span class="o">(</span><span class="n">x</span><span class="o">)</span> <span class="o">==</span> <span class="n">find</span><span class="o">(</span><span class="n">y</span><span class="o">);</span>
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div><h2 id="prim算法以顶点扩散">Prim算法(以顶点扩散)</h2>
<p>「Prim 算法」是求解「加权无向图」的「最小生成树」的另一种算法。
<a href="https://www.youtube.com/watch?v=Tg9nrD1IZ2A" target="_blank" rel="noopener noreffer">视频链接</a></p>
<p><strong>算法证明</strong>
<a href="https://www.youtube.com/watch?v=RnBhzNMNuu0" target="_blank" rel="noopener noreffer">视频链接</a></p>
<h3 id="kruskal-算法和-prim-算法区别">「Kruskal 算法」和 「Prim 算法」区别</h3>
<blockquote>
<p>在「Kruskal 算法」中，我们通过增加边数来扩大「最小生成树」；
在「Prim 算法」中，我们通过增加顶点来扩大「最小生成树」。</p>
</blockquote>
<h3 id="时间复杂度">时间复杂度</h3>
<p>普通二叉堆：$O(ElogV)O(ElogV)$。</p>
<p>斐波那契堆：$O(E+VlogV)O(E+VlogV)$。</p>
<p>$V$ 表示顶点数，$E$ 表示边数。</p>
<h3 id="空间复杂度">空间复杂度</h3>
<p>$O(V)$。</p>
<p>$V$表示顶点数。</p>
<h3 id="练习题--连接所有点的最小费用-1">练习题&ndash;连接所有点的最小费用</h3>
<blockquote>
<p>题目上面有图</p>
</blockquote>
<p><a href="https://www.youtube.com/watch?v=VRC2InE8fB0" target="_blank" rel="noopener noreffer">视频讲解</a></p>
<h3 id="解题代码-1">解题代码</h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="kd">class</span> <span class="nc">Solution</span> <span class="o">{</span>
    <span class="c1">// Prim Algorithm
</span><span class="c1"></span>    <span class="kd">public</span> <span class="kt">int</span> <span class="nf">minCostConnectPoints</span><span class="o">(</span><span class="kt">int</span><span class="o">[][]</span> <span class="n">points</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">if</span> <span class="o">(</span><span class="n">points</span> <span class="o">==</span> <span class="kc">null</span> <span class="o">||</span> <span class="n">points</span><span class="o">.</span><span class="na">length</span> <span class="o">==</span> <span class="n">0</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">return</span> <span class="n">0</span><span class="o">;</span>
        <span class="o">}</span>
        <span class="kt">int</span> <span class="n">size</span> <span class="o">=</span> <span class="n">points</span><span class="o">.</span><span class="na">length</span><span class="o">;</span>
        <span class="n">PriorityQueue</span><span class="o">&lt;</span><span class="n">Edge</span><span class="o">&gt;</span> <span class="n">pq</span> <span class="o">=</span> <span class="k">new</span> <span class="n">PriorityQueue</span><span class="o">&lt;</span><span class="n">Edge</span><span class="o">&gt;((</span><span class="n">x</span><span class="o">,</span> <span class="n">y</span><span class="o">)</span> <span class="o">-&gt;</span> <span class="n">x</span><span class="o">.</span><span class="na">cost</span> <span class="o">-</span> <span class="n">y</span><span class="o">.</span><span class="na">cost</span><span class="o">);</span>
        <span class="kt">boolean</span><span class="o">[]</span> <span class="n">visited</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">boolean</span><span class="o">[</span><span class="n">size</span><span class="o">];</span>
        <span class="kt">int</span> <span class="n">result</span> <span class="o">=</span> <span class="n">0</span><span class="o">;</span>
        <span class="kt">int</span> <span class="n">count</span> <span class="o">=</span> <span class="n">size</span> <span class="o">-</span> <span class="n">1</span><span class="o">;</span>
        <span class="c1">// Add all edges from points[0] vertexs
</span><span class="c1"></span>        <span class="k">for</span> <span class="o">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="n">1</span><span class="o">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">size</span><span class="o">;</span> <span class="n">j</span><span class="o">++)</span> <span class="o">{</span>
            <span class="c1">// Calculate the distance between two coordinates.
</span><span class="c1"></span>            <span class="kt">int</span><span class="o">[]</span> <span class="n">coordinate1</span> <span class="o">=</span> <span class="n">points</span><span class="o">[</span><span class="n">0</span><span class="o">];</span>
            <span class="kt">int</span><span class="o">[]</span> <span class="n">coordinate2</span> <span class="o">=</span> <span class="n">points</span><span class="o">[</span><span class="n">j</span><span class="o">];</span>
            <span class="kt">int</span> <span class="n">cost</span> <span class="o">=</span> <span class="n">Math</span><span class="o">.</span><span class="na">abs</span><span class="o">(</span><span class="n">coordinate1</span><span class="o">[</span><span class="n">0</span><span class="o">]</span> <span class="o">-</span> <span class="n">coordinate2</span><span class="o">[</span><span class="n">0</span><span class="o">])</span> <span class="o">+</span> <span class="n">Math</span><span class="o">.</span><span class="na">abs</span><span class="o">(</span><span class="n">coordinate1</span><span class="o">[</span><span class="n">1</span><span class="o">]</span> <span class="o">-</span> <span class="n">coordinate2</span><span class="o">[</span><span class="n">1</span><span class="o">]);</span>
            <span class="n">Edge</span> <span class="n">edge</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Edge</span><span class="o">(</span><span class="n">0</span><span class="o">,</span> <span class="n">j</span><span class="o">,</span> <span class="n">cost</span><span class="o">);</span>
            <span class="n">pq</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">edge</span><span class="o">);</span>
        <span class="o">}</span>
        <span class="n">visited</span><span class="o">[</span><span class="n">0</span><span class="o">]</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>

        <span class="k">while</span> <span class="o">(</span><span class="n">pq</span><span class="o">.</span><span class="na">size</span><span class="o">()</span> <span class="o">&gt;</span> <span class="n">0</span> <span class="o">&amp;&amp;</span> <span class="n">count</span> <span class="o">&gt;</span> <span class="n">0</span><span class="o">)</span> <span class="o">{</span>
            <span class="n">Edge</span> <span class="n">e</span> <span class="o">=</span> <span class="n">pq</span><span class="o">.</span><span class="na">poll</span><span class="o">();</span>
            <span class="kt">int</span> <span class="n">point1</span> <span class="o">=</span> <span class="n">e</span><span class="o">.</span><span class="na">point1</span><span class="o">;</span>
            <span class="kt">int</span> <span class="n">point2</span> <span class="o">=</span> <span class="n">e</span><span class="o">.</span><span class="na">point2</span><span class="o">;</span>
            <span class="kt">int</span> <span class="n">cost</span> <span class="o">=</span> <span class="n">e</span><span class="o">.</span><span class="na">cost</span><span class="o">;</span>
            <span class="k">if</span> <span class="o">(</span> <span class="o">!</span><span class="n">visited</span><span class="o">[</span><span class="n">point2</span><span class="o">]</span> <span class="o">)</span> <span class="o">{</span>
                <span class="n">result</span> <span class="o">+=</span> <span class="n">cost</span><span class="o">;</span>
                <span class="n">visited</span><span class="o">[</span><span class="n">point2</span><span class="o">]</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
                <span class="k">for</span> <span class="o">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="n">0</span><span class="o">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">size</span><span class="o">;</span> <span class="n">j</span><span class="o">++</span> <span class="o">)</span> <span class="o">{</span>
                    <span class="k">if</span> <span class="o">(</span> <span class="o">!</span><span class="n">visited</span><span class="o">[</span><span class="n">j</span><span class="o">]</span> <span class="o">)</span> <span class="o">{</span>
                        <span class="kt">int</span> <span class="n">distance</span> <span class="o">=</span> <span class="n">Math</span><span class="o">.</span><span class="na">abs</span><span class="o">(</span><span class="n">points</span><span class="o">[</span><span class="n">point2</span><span class="o">][</span><span class="n">0</span><span class="o">]</span> <span class="o">-</span> <span class="n">points</span><span class="o">[</span><span class="n">j</span><span class="o">][</span><span class="n">0</span><span class="o">])</span> <span class="o">+</span> <span class="n">Math</span><span class="o">.</span><span class="na">abs</span><span class="o">(</span><span class="n">points</span><span class="o">[</span><span class="n">point2</span><span class="o">][</span><span class="n">1</span><span class="o">]</span> <span class="o">-</span> <span class="n">points</span><span class="o">[</span><span class="n">j</span><span class="o">][</span><span class="n">1</span><span class="o">]);</span>
                        <span class="n">pq</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="k">new</span> <span class="n">Edge</span><span class="o">(</span><span class="n">point2</span><span class="o">,</span> <span class="n">j</span><span class="o">,</span> <span class="n">distance</span><span class="o">));</span>
                    <span class="o">}</span>
                <span class="o">}</span>
                <span class="n">count</span><span class="o">--;</span>
            <span class="o">}</span>
        <span class="o">}</span>
        <span class="k">return</span> <span class="n">result</span><span class="o">;</span>
    <span class="o">}</span>

    <span class="kd">class</span> <span class="nc">Edge</span> <span class="o">{</span>
        <span class="kt">int</span> <span class="n">point1</span><span class="o">;</span>
        <span class="kt">int</span> <span class="n">point2</span><span class="o">;</span>
        <span class="kt">int</span> <span class="n">cost</span><span class="o">;</span>

        <span class="n">Edge</span><span class="o">(</span><span class="kt">int</span> <span class="n">point1</span><span class="o">,</span> <span class="kt">int</span> <span class="n">point2</span><span class="o">,</span> <span class="kt">int</span> <span class="n">cost</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="na">point1</span> <span class="o">=</span> <span class="n">point1</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="na">point2</span> <span class="o">=</span> <span class="n">point2</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="na">cost</span> <span class="o">=</span> <span class="n">cost</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div><div class="post-footer" id="post-footer">
    <div class="post-info"><div class="post-info-tag"><span><a href="/tags/%E5%85%B3%E4%BA%8E%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91%E7%9A%84%E4%B8%80%E5%88%87/">关于最小生成树的一切</a>
                </span></div><div class="post-info-line"><div class="post-info-mod">
                <span>更新于 2022-12-19</span>
            </div><div class="post-info-mod"></div>
        </div><div class="post-info-share">
            <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://acking-you.github.io/posts/%E5%85%B3%E4%BA%8E%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91%E7%9A%84%E4%B8%80%E5%88%87/" data-title="关于最小生成树的一切" data-hashtags="关于最小生成树的一切"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://acking-you.github.io/posts/%E5%85%B3%E4%BA%8E%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91%E7%9A%84%E4%B8%80%E5%88%87/" data-hashtag="关于最小生成树的一切"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://acking-you.github.io/posts/%E5%85%B3%E4%BA%8E%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91%E7%9A%84%E4%B8%80%E5%88%87/" data-title="关于最小生成树的一切" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://acking-you.github.io/posts/%E5%85%B3%E4%BA%8E%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91%E7%9A%84%E4%B8%80%E5%88%87/" data-title="关于最小生成树的一切"><i class="fab fa-line fa-fw"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://acking-you.github.io/posts/%E5%85%B3%E4%BA%8E%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91%E7%9A%84%E4%B8%80%E5%88%87/" data-title="关于最小生成树的一切" data-image="https://img-blog.csdnimg.cn/img_convert/acea126d07748d6630f37b1b481e5d73.png#pic_center"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://acking-you.github.io/posts/%E5%85%B3%E4%BA%8E%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91%E7%9A%84%E4%B8%80%E5%88%87/" data-title="关于最小生成树的一切" data-description="关于最小生成树的一切"><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://acking-you.github.io/posts/%E5%85%B3%E4%BA%8E%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91%E7%9A%84%E4%B8%80%E5%88%87/" data-title="关于最小生成树的一切" data-description="关于最小生成树的一切"><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://acking-you.github.io/posts/%E5%85%B3%E4%BA%8E%E6%9C%80%E5%B0%8F%E7%94%9F%E6%88%90%E6%A0%91%E7%9A%84%E4%B8%80%E5%88%87/" data-title="关于最小生成树的一切"><i class="fab fa-evernote fa-fw"></i></a></span>
        </div></div><div class="post-nav"><a href="/posts/zipgzipbzip2tar%E6%9C%89%E4%BD%95%E8%81%94%E7%B3%BB/" class="prev" rel="prev" title="zip、gzip、bzip2、tar有何联系？"><i class="fas fa-angle-left fa-fw"></i>Previous Post</a>
            <a href="/posts/%E5%85%B3%E4%BA%8E%E5%B9%B6%E6%9F%A5%E9%9B%86%E7%9A%84%E4%B8%80%E5%88%87/" class="next" rel="next" title="关于并查集的一切">Next Post<i class="fas fa-angle-right fa-fw"></i></a></div></div>
</div></article></div>
            </main>
            <footer class="footer"><div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.86.0">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/khusika/FeelIt" target="_blank" rel="noopener noreffer" title="FeelIt 1.0.1"><i class="fas fa-hand-holding-heart fa-fw"></i> FeelIt</a>
        </div><div class="footer-line" itemscope itemtype="http://schema.org/CreativeWork"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2023</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/"></a></span></div>
</div>
</footer>
        </div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-chevron-up fa-fw"></i>
            </a></div><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><script src="/lib/autocomplete/autocomplete.min.js"></script><script src="/lib/lunr/lunr.min.js"></script><script src="/lib/lunr/lunr.stemmer.support.min.js"></script><script src="/lib/lunr/lunr.zh.min.js"></script><script src="/lib/lazysizes/lazysizes.min.js"></script><script src="/lib/clipboard/clipboard.min.js"></script><script src="/lib/sharer/sharer.min.js"></script><script src="/lib/katex/katex.min.js"></script><script src="/lib/katex/auto-render.min.js"></script><script src="/lib/katex/copy-tex.min.js"></script><script src="/lib/katex/mhchem.min.js"></script><script>window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":200},"comment":{},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":100,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script src="/js/theme.min.js"></script></body></html>
